package com.cyh;

import com.cyh.dao.OrderMapper;
import com.cyh.dao.UserMapper;
import com.cyh.domain.Order;
import com.cyh.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.logging.Logger;

public class MapperTest2 {
    private static Logger logger = Logger.getLogger("cyh");

    private OrderMapper mapper;
    SqlSession sqlSession;
    //一对一
    @Before
    public void before() throws IOException {
        //获得核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        //获得session工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获得session回话对象
        sqlSession = sqlSessionFactory.openSession(); //也可以传一个参数，是否自动提交事务，默认要手动提交更新事务的。
        mapper = sqlSession.getMapper(OrderMapper.class);
    }

    @Test
    public void testFindAllOrder() {
        List<Order> orderList = mapper.findAll();
        logger.info(orderList.toString());
        sqlSession.commit();
        sqlSession.close();

    }





}
